home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / FreshBar / Source / FreshBar_ARexxPort.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-29  |  12.8 KB  |  569 lines

  1. //****************************************************************//
  2. // Filename:    FreshBar_ARexxPort.cpp
  3. // Autor:       Christian Taulien of Strange Intelligence
  4. // Purpose:     Testprogram for the SIFC
  5. // Creation:    11. Mai 1998
  6. //****************************************************************//
  7.  
  8. #include <intuition/intuition.h>
  9.  
  10. #include <clib/intuition_protos.h>
  11. #include <clib/dos_protos.h>
  12.  
  13. #include "global.h"
  14. #include "FreshBar_ARexxPort.h"
  15. #include "FreshLocale.h"
  16. #include "WindowList.h"
  17.  
  18. #define RXLONG(x) *((LONG *) x)
  19.  
  20. struct ARexxCommand comm1 =  { "QUIT", NULL, RXID_QUIT };
  21. struct ARexxCommand comm2 =  { "ABOUT", NULL, RXID_INFO };
  22. struct ARexxCommand comm3 =  { "TESTIT", NULL, RXID_TEST };
  23. struct ARexxCommand comm4 =  { "CREATEBARWINDOW", "TITLE,BUTTONTEXT,SCREEN,CLOSEGADGET/S", RXID_CREATEWIN };
  24. struct ARexxCommand comm5 =  { "DELETEBARWINDOW", "WINHANDLE/N/A", RXID_DELETEWIN };
  25. struct ARexxCommand comm6 =  { "OPENBARWINDOW", "WINHANDLE/N/A,TITLE", RXID_OPENWIN };
  26. struct ARexxCommand comm7 =  { "CLOSEBARWINDOW", "WINHANDLE/N/A", RXID_CLOSEWIN };
  27. struct ARexxCommand comm8 =  { "ADDBAR", "WINHANDLE/N/A,MAXVALUE/N,CURRENTVALUE/N,NAME/F", RXID_ADDBAR };
  28. struct ARexxCommand comm9 =  { "REMOVEBAR", "WINHANDLE/N/A,BARHANDLE/N/A", RXID_REMBAR };
  29. struct ARexxCommand comm10 = { "CLOSEALLBARWINDOWS", NULL, RXID_CLOSEALL };
  30. struct ARexxCommand comm11 = { "SETCURRENT", "WINHANDLE/N/A,BARHANDLE/N/A,VALUE/N/A", RXID_SETCURVAL };
  31. struct ARexxCommand comm12 = { "SETMAXIMUM", "WINHANDLE/N/A,BARHANDLE/N/A,VALUE/N/A", RXID_SETMAXVAL };
  32. struct ARexxCommand comm13 = { "SETFILLPEN", "WINHANDLE/N/A,BARHANDLE/N/A,FILLPEN/N/A", RXID_SETFILLPEN };
  33. struct ARexxCommand comm14 = { "SETBACKPEN", "WINHANDLE/N/A,BARHANDLE/N/A,BACKPEN/N/A", RXID_SETBACKPEN };
  34. struct ARexxCommand comm15 = { "SETPROGRESSMODE", "WINHANDLE/N/A,BARHANDLE/N/A,MODE/N/A", RXID_SETPROGRESSMODE };
  35. struct ARexxCommand comm16 = { "SETBARWINDOWWIDTH", "WINHANDLE/N/A,WIDTH/N/A", RXID_SETWINWIDTH };
  36. struct ARexxCommand comm17 = { "SETBARWINDOWPOS", "WINHANDLE/N/A,X/N,Y/N", RXID_SETWINPOS };
  37. struct ARexxCommand comm18 = { "TESTOKBUTTON", "WINHANDLE/N/A", RXID_TESTOKBUTTON };
  38. struct ARexxCommand comm19 = { "DELAY", "MILLISECS/N", RXID_DELAY };
  39.  
  40. struct ARexxCommand *FreshBarARexxCommandList[] =
  41. {
  42.   &comm1,  &comm2,  &comm3,  &comm4,  &comm5,  &comm6,  &comm7,  &comm8,
  43.   &comm9,  &comm10, &comm11, &comm12, &comm13, &comm14, &comm15, &comm16,
  44.   &comm17, &comm18, &comm19, 0
  45. };
  46.  
  47. char *glob_sErrString = "error";
  48.  
  49. extern CatalogC *glob_poCatalog;
  50. extern BarWindowListC *glob_poBWList;
  51.  
  52. BOOL FreshBarARexxPortC::RX_Quit(LONG *args)
  53. /*S*/
  54. {
  55.   TRACE("Entry");
  56. BOOL done=TRUE;
  57. return done;
  58. }
  59. /*E*/
  60. void FreshBarARexxPortC::RX_Info(LONG *args)
  61. /*S*/
  62. {
  63.   static struct EasyStruct about =
  64.   {
  65.     sizeof(struct EasyStruct),
  66.     0,
  67.     0,  // titel
  68.     0,  // text
  69.     0   // gadgets
  70.   };
  71.  
  72.   TRACE("Entry");
  73.   about.es_Title = glob_poCatalog->getString(T_INFOTITLE);
  74.   about.es_TextFormat = glob_poCatalog->getString(T_INFOTEXT);
  75.   about.es_GadgetFormat = glob_poCatalog->getString(T_INFOWEITER);
  76.  
  77.   EasyRequestArgs(NULL, &about, NULL, NULL);
  78. }
  79. /*E*/
  80. void FreshBarARexxPortC::RX_Test(LONG *args)
  81. /*S*/
  82. {
  83.   TRACE("Entry");
  84.   BarWindowListC oBWList;
  85.   BarWindowNodeC *poBWNode = oBWList.addBarWindow("Hallo!", "_Weiter", NULL, TRUE);
  86.  
  87.   poBWNode->openBarWindow();
  88.   Delay(50);
  89.  
  90.   BarNodeC *poBarNode  = poBWNode->addBar("Copy: ", 2000);
  91.   poBarNode->setCurrentVal(42*4);
  92.  
  93.   Delay(50);
  94.  
  95.   BarNodeC *poBarNode2 = poBWNode->addBar("Kuckuck!!!: ", 2000);
  96.   Delay(20);
  97.   poBarNode2->setCurrentVal(100);
  98.  
  99. //  poBWNode->addBar("Test: ", 100)->setCurrentVal(25);
  100. //  poBWNode->addBar("A: ", 100)->setCurrentVal(75);
  101. //  poBWNode->addBar("Das ist ein Test: ", 100)->setCurrentVal(100);
  102.  
  103.   poBWNode->setBarWindowWidth(800);
  104.   Delay(30);
  105.  
  106.   for (ULONG i=2050; i>0; i--)
  107.   {
  108.     poBarNode->setCurrentVal(i);
  109.     poBarNode2->setCurrentVal(2050-i);
  110.     poBWNode->refreshBars();
  111.   } // for
  112.   //Delay(150);
  113.  
  114.   Delay(20);
  115.   poBWNode->removeBar(poBarNode->getBarID());
  116.   Delay(20);
  117.   poBWNode->removeBar(poBarNode2->getBarID());
  118.   Delay(20);
  119. }
  120. /*E*/
  121. StringC FreshBarARexxPortC::RX_CreateWin(LONG *args)
  122. /*S*/
  123. {
  124.   TRACE("Entry");
  125.  
  126.   // titel ermitteln
  127.   char *sTitle = NULL;
  128.   if (args[0])
  129.   {
  130.     sTitle = (char *) args[0];
  131.   } // if
  132.  
  133.   // Buttontext ermitteln
  134.   char *sButtonText = "";
  135.   if (args[1])
  136.   {
  137.     sButtonText = (char *) args[1];
  138.   } // if
  139.  
  140.   // Screenname ermitteln
  141.   char *sScreen = NULL;
  142.   if (args[2])
  143.   {
  144.     sScreen = (char *) args[2];
  145.   } // if
  146.  
  147.   BOOL bCloseGad = args[3] ? TRUE : FALSE;
  148.  
  149.   BarWindowNodeC *poBWNode = glob_poBWList->addBarWindow(sTitle, sButtonText, sScreen, bCloseGad);
  150.   if (poBWNode)
  151.   {
  152.     StringC oTemp(15);
  153.     oTemp.formatString("%d", poBWNode->getBarWindowID());
  154.     return oTemp;
  155.   } // if
  156. return glob_sErrString;
  157. }
  158. /*E*/
  159. void FreshBarARexxPortC::RX_DeleteWin(LONG *args)
  160. /*S*/
  161. {
  162.   TRACE("Entry");
  163.   if (!args[0])
  164.   {
  165.     return;
  166.   } // if
  167.  
  168.   glob_poBWList->removeBarWindow(RXLONG(args[0]));
  169. }
  170. /*E*/
  171. void FreshBarARexxPortC::RX_OpenWin(LONG *args)
  172. /*S*/
  173. {
  174.   TRACE("Entry");
  175.   if (!args[0])
  176.   {
  177.     return;
  178.   } // if
  179.  
  180.   BarWindowNodeC *poNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  181.  
  182.   if (poNode)
  183.   {
  184.     if (args[1])
  185.     {
  186.       poNode->setBarWindowTitle((char *) args[1]);
  187.     } // if
  188.     poNode->openBarWindow();
  189.   } // if
  190. }
  191. /*E*/
  192. void FreshBarARexxPortC::RX_CloseWin(LONG *args)
  193. /*S*/
  194. {
  195.   TRACE("Entry");
  196.   if (!args[0])
  197.   {
  198.     return;
  199.   } // if
  200.  
  201.   BarWindowNodeC *poNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  202.  
  203.   if (poNode)
  204.   {
  205.     poNode->closeBarWindow();
  206.   } // if
  207. }
  208. /*E*/
  209. StringC FreshBarARexxPortC::RX_AddBar(LONG *args)
  210. /*S*/
  211. {
  212.   TRACE("Entry");
  213.   if (!args[0])
  214.   {
  215.     return glob_sErrString;
  216.   } // if
  217.  
  218.   BarWindowNodeC *poBarWinNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  219.  
  220.   if (poBarWinNode)
  221.   {
  222.     // bestimme den Namen des Balkens
  223.     char *sBarName = "";
  224.     if (args[3])
  225.     {
  226.       sBarName = (char *) args[3];
  227.     } // if
  228.  
  229.     // bestimme den Maximalweert
  230.     ULONG ulMaxValue = 100;
  231.     if (args[1])
  232.     {
  233.       ulMaxValue = RXLONG(args[1]);
  234.     } // if
  235.  
  236.     BarNodeC *poBarNode = poBarWinNode->addBar(sBarName, ulMaxValue);
  237.     if (poBarNode)
  238.     {
  239.       // den Current-Value festlegen
  240.       if (args[2])
  241.       {
  242.         poBarNode->setCurrentVal(RXLONG(args[2]));
  243.         poBarWinNode->refreshBars();
  244.       } // if
  245.  
  246.       StringC oTemp(15);
  247.       oTemp.formatString("%d", poBarNode->getBarID());
  248.       return oTemp;
  249.     } // if
  250.   } // if
  251. return glob_sErrString;
  252. }
  253. /*E*/
  254. void FreshBarARexxPortC::RX_RemoveBar(LONG *args)
  255. /*S*/
  256. {
  257.   TRACE("Entry");
  258.   if (!args[0] || !args[1])
  259.   {
  260.     return;
  261.   } // if
  262.  
  263.   BarWindowNodeC *poBarWinNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  264.  
  265.   if (poBarWinNode)
  266.   {
  267.     poBarWinNode->removeBar(RXLONG(args[1]));
  268.   } // if
  269. }
  270. /*E*/
  271. void FreshBarARexxPortC::RX_CloseAllWindows(LONG *args)
  272. /*S*/
  273. {
  274.   TRACE("Entry");
  275.   glob_poBWList->removeAll();
  276. }
  277. /*E*/
  278. void FreshBarARexxPortC::RX_SetCurValue(LONG *args)
  279. /*S*/
  280. {
  281.   TRACE("Entry");
  282.   if (!args[0] || !args[1] || !args[2])
  283.   {
  284.     return;
  285.   } // if
  286.  
  287.   BarWindowNodeC *poBarWinNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  288.  
  289.   if (poBarWinNode)
  290.   {
  291.     BarNodeC *poBarNode = poBarWinNode->findBarNode(RXLONG(args[1]));
  292.     if (poBarNode)
  293.     {
  294.       // den Current-Value festlegen
  295.       poBarNode->setCurrentVal(RXLONG(args[2]));
  296.       poBarWinNode->refreshBars();
  297.     } // if
  298.   } // if
  299. return;
  300. }
  301. /*E*/
  302. void FreshBarARexxPortC::RX_SetMaxValue(LONG *args)
  303. /*S*/
  304. {
  305.   TRACE("Entry");
  306.   if (!args[0] || !args[1] || !args[2])
  307.   {
  308.     return;
  309.   } // if
  310.  
  311.   BarWindowNodeC *poBarWinNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  312.  
  313.   if (poBarWinNode)
  314.   {
  315.     BarNodeC *poBarNode = poBarWinNode->findBarNode(RXLONG(args[1]));
  316.     if (poBarNode)
  317.     {
  318.       // den Current-Value festlegen
  319.       poBarNode->setMaxVal(RXLONG(args[2]));
  320.       poBarWinNode->refreshBars();
  321.     } // if
  322.   } // if
  323. return;
  324. }
  325. /*E*/
  326. void FreshBarARexxPortC::RX_SetFillPen(LONG *args)
  327. /*S*/
  328. {
  329.   TRACE("Entry");
  330.   if (!args[0] || !args[1] || !args[2])
  331.   {
  332.     return;
  333.   } // if
  334.  
  335.   BarWindowNodeC *poBarWinNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  336.  
  337.   if (poBarWinNode)
  338.   {
  339.     BarNodeC *poBarNode = poBarWinNode->findBarNode(RXLONG(args[1]));
  340.     if (poBarNode)
  341.     {
  342.       // den Current-Value festlegen
  343.       poBarNode->setFillPen(RXLONG(args[2]));
  344.       poBarWinNode->refreshBars();
  345.     } // if
  346.   } // if
  347. return;
  348. }
  349. /*E*/
  350. void FreshBarARexxPortC::RX_SetBackPen(LONG *args)
  351. /*S*/
  352. {
  353.   TRACE("Entry");
  354.   if (!args[0] || !args[1] || !args[2])
  355.   {
  356.     return;
  357.   } // if
  358.  
  359.   BarWindowNodeC *poBarWinNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  360.  
  361.   if (poBarWinNode)
  362.   {
  363.     BarNodeC *poBarNode = poBarWinNode->findBarNode(RXLONG(args[1]));
  364.     if (poBarNode)
  365.     {
  366.       // den Current-Value festlegen
  367.       poBarNode->setBackPen(RXLONG(args[2]));
  368.       poBarWinNode->refreshBars();
  369.     } // if
  370.   } // if
  371. return;
  372. }
  373. /*E*/
  374. void FreshBarARexxPortC::RX_SetProgressMode(LONG *args)
  375. /*S*/
  376. {
  377.   TRACE("Entry");
  378.   if (!args[0] || !args[1] || !args[2])
  379.   {
  380.     return;
  381.   } // if
  382.  
  383.   BarWindowNodeC *poBarWinNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  384.  
  385.   if (poBarWinNode)
  386.   {
  387.     BarNodeC *poBarNode = poBarWinNode->findBarNode(RXLONG(args[1]));
  388.     if (poBarNode)
  389.     {
  390.       // den Current-Value festlegen
  391.       poBarNode->setProgressMode((BarNodeC::ProgressMode) RXLONG(args[2]));
  392.       poBarWinNode->refreshBars();
  393.     } // if
  394.   } // if
  395. return;
  396. }
  397. /*E*/
  398. void FreshBarARexxPortC::RX_SetWindowWidth(LONG *args)
  399. /*S*/
  400. {
  401.   TRACE("Entry");
  402.   if (!args[0] || !args[1])
  403.   {
  404.     return;
  405.   } // if
  406.  
  407.   BarWindowNodeC *poBarWinNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  408.  
  409.   if (poBarWinNode)
  410.   {
  411.     poBarWinNode->setBarWindowWidth(RXLONG(args[1]));
  412.   } // if
  413. return;
  414. }
  415. /*E*/
  416. void FreshBarARexxPortC::RX_SetWindowPos(LONG *args)
  417. /*S*/
  418. {
  419.   TRACE("Entry");
  420.   if (!args[0])
  421.   {
  422.     return;
  423.   } // if
  424.  
  425.   BarWindowNodeC *poBarWinNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  426.  
  427.   if (poBarWinNode)
  428.   {
  429.     int iPosX = -2;
  430.     if (args[1])
  431.     {
  432.       iPosX = RXLONG(args[1]);
  433.     } // if
  434.  
  435.     int iPosY = -2;
  436.     if (args[2])
  437.     {
  438.       iPosY = RXLONG(args[2]);
  439.     } // if
  440.  
  441.     poBarWinNode->setBarWindowPos(iPosX, iPosY);
  442.   } // if
  443. return;
  444. }
  445. /*E*/
  446. StringC FreshBarARexxPortC::RX_TestOkButton(LONG *args)
  447. /*S*/
  448. {
  449.   TRACE("Entry");
  450.   if (!args[0])
  451.   {
  452.     return glob_sErrString;
  453.   } // if
  454.  
  455.   BarWindowNodeC *poBarWinNode = glob_poBWList->findBarWindowNode(RXLONG(args[0]));
  456.  
  457.   if (poBarWinNode)
  458.   {
  459.     return poBarWinNode->testOKButton() ? "1" : "0";
  460.   } // if
  461. return glob_sErrString;
  462. }
  463. /*E*/
  464. void FreshBarARexxPortC::RX_Delay(LONG *args)
  465. /*S*/
  466. {
  467.   TRACE("Entry");
  468.   int iDelay = 50;
  469.   if (args[0])
  470.   {
  471.     iDelay = RXLONG(args[0]);
  472.   } // if
  473.  
  474.   Delay(iDelay);
  475. }
  476. /*E*/
  477.  
  478. BOOL FreshBarARexxPortC::dispatchARexxCommand(ULONG arg_ulCmdID, LONG *arg_alArgArray, LONG &arg_rlRC, LONG &arg_rlRC2, StringC &roResult)
  479. /*S*/
  480. {
  481. BOOL done = FALSE;
  482.   TRACE("Entry");
  483.   roResult.emptyString();
  484.   arg_rlRC = NULL;
  485.   arg_rlRC2 = NULL;
  486.  
  487.   switch (arg_ulCmdID)
  488.   {
  489.     case RXID_QUIT:
  490.       done = RX_Quit(arg_alArgArray);
  491.       break;
  492.     case RXID_INFO:
  493.       RX_Info(arg_alArgArray);
  494.       break;
  495.     case RXID_TEST:
  496.       RX_Test(arg_alArgArray);
  497.       break;
  498.     case RXID_CREATEWIN:
  499.       roResult = RX_CreateWin(arg_alArgArray);
  500.       if (roResult == glob_sErrString)
  501.       {               
  502.         roResult.emptyString();
  503.         arg_rlRC = 5;
  504.       } // if
  505.       break;
  506.     case RXID_DELETEWIN:
  507.       RX_DeleteWin(arg_alArgArray);
  508.       break;
  509.     case RXID_OPENWIN:
  510.       RX_OpenWin(arg_alArgArray);
  511.       break;
  512.     case RXID_CLOSEWIN:
  513.       RX_CloseWin(arg_alArgArray);
  514.       break;
  515.     case RXID_ADDBAR:
  516.       roResult = RX_AddBar(arg_alArgArray);
  517.       if (roResult == glob_sErrString)
  518.       {
  519.         roResult.emptyString();
  520.         arg_rlRC = 5;
  521.       } // if
  522.       break;
  523.     case RXID_REMBAR:
  524.       RX_RemoveBar(arg_alArgArray);
  525.       break;
  526.     case RXID_CLOSEALL:
  527.       RX_CloseAllWindows(arg_alArgArray);
  528.       break;
  529.     case RXID_SETCURVAL:
  530.       RX_SetCurValue(arg_alArgArray);
  531.       break;
  532.     case RXID_SETMAXVAL:
  533.       RX_SetMaxValue(arg_alArgArray);
  534.       break;
  535.     case RXID_SETFILLPEN:
  536.       RX_SetFillPen(arg_alArgArray);
  537.       break;
  538.     case RXID_SETBACKPEN:
  539.       RX_SetBackPen(arg_alArgArray);
  540.       break;
  541.     case RXID_SETPROGRESSMODE:
  542.       RX_SetProgressMode(arg_alArgArray);
  543.       break;
  544.     case RXID_SETWINWIDTH:
  545.       RX_SetWindowWidth(arg_alArgArray);
  546.       break;
  547.     case RXID_SETWINPOS:
  548.       RX_SetWindowPos(arg_alArgArray);
  549.       break;
  550.     case RXID_TESTOKBUTTON:
  551.       roResult = RX_TestOkButton(arg_alArgArray);
  552.       if (roResult == glob_sErrString)
  553.       {
  554.         roResult.emptyString();
  555.         arg_rlRC = 5;
  556.       } // if
  557.       break; 
  558.     case RXID_DELAY:
  559.       RX_Delay(arg_alArgArray);
  560.       break;
  561.     default:
  562.       inherited::dispatchARexxCommand(arg_ulCmdID, arg_alArgArray, arg_rlRC, arg_rlRC2, roResult);
  563.       break;
  564.   } // switch
  565. return done;
  566. }
  567. /*E*/
  568.  
  569.